#include "NetworkController.h"

#include "Network.h"

NetworkController::NetworkController(int dataLength, short entityReference) : m_dataLength(dataLength), m_entityRef(entityReference)
{
	m_buffer = new RingBuffer<std::string, long, RING_BUFFER_LENGTH>;
	
	//Add this controller to the Network
	Network::Get()->AddNetworkController(this);
}

std::string *NetworkController::GetData(long pos)
{
	//Return a pointer to the requested positon in the ring buffer
	return (m_buffer->Get(pos));
}

void NetworkController::AddData(long tick, char *data)
{
	//Create a new string for insertion and add data
	std::string string;
	string.reserve(m_dataLength);
	for(int i = 0; i < m_dataLength; ++i)
	{
		string.push_back(data[i]);
	}

	//Add string to the ring buffer
	m_buffer->Push(string, tick);
}